// import axios from 'axios'
import _time from '../utils/_time';
import _md5 from '../utils/_md5';
import _base64 from '../utils/_base64';
import _config from "./_config";
import _layer from "./_layer";
import _object from "../utils/_object";


//接口超时时间
const __timeout = 180 * 1000;

//type
let __method = {
  _get: 'GET',
  _post: 'POST',
  _put: 'PUT',
  _del: 'DELETE'
};

//content-type
let __content_type = {
  _primary: 'application/x-www-form-urlencoded',
  _file: 'multipart/form-data', //false
  _json: 'application/json;charset=utf-8',
  _xml: 'text/xml'
};

//data-type
let __data_type = {
  _json: 'json',
  _xml: 'XML'
};



//ajax私有函数
let __ajax = function (clickid, method, data_type, timeout) {


  let data = 
  {
    "event_type": "form", 
    "context": {
        "ad": {
            "callback": clickid,//callback 这里需要填写的就是从启动参数里获取的 clickid
        }
       
    },
    "timestamp": _time._current(13)
}


  let header = {};
  header['Content-Type'] = __content_type._json;

  return new Promise((reslove, reject) => {
    tt.request({
      url: 'https://analytics.oceanengine.com/api/v2/conversion',
      data: data,
      header: header,
      timeout: timeout,
      method: method,
      dataType: data_type,
      success: function (res) {
        console.log(res);
      },
      fail: function (err) {
        console.log(err);
        //提示框 - 网络异常 TODO
      },
      complete: function (res) {
      }
    });
  });
};



//定义类
let _request = {

  //成功标记
  success: 0,
  //失败标记
  fail: -1,

  //post请求
  _post: function (clickid) {
    //参数
    return __ajax(clickid, __method._post, __data_type._json, __timeout);
  },

};

//导出
export default _request;